package com.eggplant.timetools.utils;

import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.util.Log;

public class MyLog {
	public static String LOGTAG="ydy_log";
	final private static boolean myDebug = false;
	
	public static void i (String msg) {
		if (myDebug)
			Log.i(LOGTAG, msg);
	}
	public static void v (String msg) {
		if (myDebug)
			Log.i(LOGTAG, msg);
	}
	
	public static boolean isDebug(){
		return myDebug;
	}
	
	public static void d(String tag, String msg) {
		if (myDebug)
			Log.d(tag, msg);
	}

	public static void e(String tag, String msg) {
		if (myDebug)
			Log.e(tag, msg);
	}

	public static void i(String tag, String msg) {
		if (myDebug)
			Log.i(tag, msg);
	}

	public static void v(String tag, String msg) {
		if (myDebug)
			Log.v(tag, msg);
	}

	public static void w(String tag, String msg) {
		if (myDebug)
			Log.w(tag, msg);
	}

	public static void w(String tag, String msg, Throwable tr)
	{
		if (myDebug)
			Log.w(tag, msg, tr);
	}
	
	public static void e(String tag, String msg, Throwable tr)
	{
		if (myDebug)
			Log.e(tag, msg, tr);
	}
	
	private static final SimpleDateFormat DATA_FORMAT = new SimpleDateFormat(
			"yyyy-MM-dd HH:mm:ss.SSS");
	
	private static final String sep = " ";
	static{
		File root =new File("/sdcard/eggplant_timetools");
		if(!root.exists()){
			root.mkdirs();
		}
	}
	
	public static void Logtofile(String str)
	{
		if(!MyLog.isDebug()){
			return;
		}
		try{
			
			MyLog.i("agjlog", str);
		File logFile = new File("/sdcard/eggplant_timetools/logs.txt");
		FileOutputStream logStream = new FileOutputStream(logFile, true);
		logStream.write(DATA_FORMAT.format(new Date(System.currentTimeMillis())).getBytes());
		logStream.write(sep.getBytes());
		logStream.write(str.getBytes());
		logStream.write("\r\n".getBytes());
		logStream.flush();
		logStream.close();
		}
		catch (Exception e) {
		}
	}
}
